(add-hook 
 'eshell-first-time-mode-hook
 (lambda ()
   (setq eshell-visual-commands 
	 (append '("mutt" "vi"  "screen" "lftp" "ipython" "telnet" "ssh" "top" "bash")
		 eshell-visual-commands))))

(defun eshell/ssh (&rest args)
  (let* ((args (append (eshell-flatten-list args) '("-X")))
         (term-buf (generate-new-buffer (car args)))
         (eshell-buf (current-buffer)))
    (save-current-buffer
      (switch-to-buffer term-buf)
      (term-mode)
      (set (make-local-variable 'eshell-parent-buffer) eshell-buf)
      (term-exec term-buf (car args) "ssh" nil args)
      (let ((proc (get-buffer-process term-buf)))
	(if (and proc (eq 'run (process-status proc)))
	    (set-process-sentinel proc 'eshell-term-sentinel)
	  (error "Failed to invoke visual command")))
      (term-char-mode)
      (if eshell-escape-control-x
	  (term-set-escape-char ?\C-x))))
  nil)

(setq extra-path '("~/bin"))
(setq extra-path (mapcar 'expand-file-name extra-path))
(setq exec-path (append exec-path extra-path))
(setenv "PATH" (concat (getenv "PATH") ":" (mapconcat 'identity extra-path ":")))
(setenv "VISUAL" "emacsclient -a gedit")
(setenv "EDITOR" "emacsclient -a gedit")
(setenv "GIT_SSH" "socks-ssh")
(setenv "GIT_PROXY_COMMAND" "socks-gw")
(global-set-key (kbd "<f9>") 'eshell)

(provide 'shell-init)
